import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import '../../config/public_text.dart';
import '../text_field/public_text_field.dart';
import 'horizontal_item.dart';

/// FileName text_field_item
///
/// @Author lax
/// @Date 2023/5/10
///
/// @Description

class TextFieldItem extends HorizontalItem {
  TextFieldItem({
    super.key,
    super.title,
    super.value,
    String? hintText,
    super.enable = true,
    super.required = false,
    EdgeInsets? padding,
    super.titleStyle,
    super.valueStyle,
    super.unableTitleStyle,
    super.unableValueStyle,
    super.hintTextStyle,
    super.titleWidth,
    super.flex,
    super.leftWidget,
    super.rightWidget,
    final ValueChanged<String>? onChanged,
    final int? maxLines = 1,
    final bool obscureText = false,
    final TextInputType? keyboardType,
    final List<TextInputFormatter>? inputFormatters,
  }) : super(
          padding: (padding == null && HorizontalItem.defaultPadding == null)
              ? null
              : EdgeInsets.only(
                  left:
                      padding?.left ?? HorizontalItem.defaultPadding?.left ?? 0,
                  right: padding?.right ??
                      HorizontalItem.defaultPadding?.right ??
                      0),
          hintText: hintText ?? PublicText.pleaseInput,
          valueWidget: PublicTextField(
            enable: enable,
            text: value,
            onChanged: onChanged,
            hintText: enable ? hintText : '',
            style: valueStyle,
            unableStyle: unableValueStyle,
            hintStyle: hintTextStyle,
            padding: (padding == null && HorizontalItem.defaultPadding == null)
                ? null
                : EdgeInsets.only(
                    top:
                        padding?.top ?? HorizontalItem.defaultPadding?.top ?? 0,
                    bottom: padding?.bottom ??
                        HorizontalItem.defaultPadding?.bottom ??
                        0),
            textAlign: title == null ? TextAlign.left : TextAlign.right,
            maxLines: maxLines,
            obscureText: obscureText,
            keyboardType: keyboardType ?? TextInputType.text,
            inputFormatters: inputFormatters,
            showClearButton: false,
          ),
        );
}
